﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using GrayParrot.Web.Controls;
using GrayParrot.Core.Filters;
using Test.DAL;


namespace Dashboard.BL.ResultSet
{
    public class EmployeesResultSet : ResultSet<Employee>
	{
        public EmployeesResultSet(DTParameters param, IQueryable<Employee> result)
            : base(param, result)
        {
        }

        public override Expression<Func<Employee, bool>> ApplyGeneralFilter(string searchPattern)
        {
            var predicate = PredicateBuilder.False<Employee>();

            if (!string.IsNullOrWhiteSpace(searchPattern))
            {
                predicate = predicate.Or(im => im.FirstName != null && im.FirstName.ToString().Contains(searchPattern));
                predicate = predicate.Or(im => im.LastName != null && im.LastName.ToString().Contains(searchPattern));
                predicate = predicate.Or(im => im.Title != null && im.Title.ToString().Contains(searchPattern));
            }

            return predicate;
        }

        public override Expression<Func<Employee, bool>> ApplyGeneralColumnsFilter(List<string> columnSearch)
        {
            var predicate = PredicateBuilder.True<Employee>();

            //string m_id = columnSearch[ColumnIndex];
            //string m_title = columnSearch[ColumnIndex];
            //string m_name = columnSearch[ColumnIndex];
            //string m_company = columnSearch[ColumnIndex];


            //if (!string.IsNullOrWhiteSpace(m_title))
            //{
            //    predicate = predicate.And(im => im.ContactTitle.Contains(m_title));
            //}

            //if (!string.IsNullOrWhiteSpace(m_name))
            //{
            //    predicate = predicate.And(im => im.ContactName.Contains(m_name));
            //}

            //if (!string.IsNullOrWhiteSpace(m_company))
            //{
            //    predicate = predicate.And(im => im.CompanyName.Contains(m_company));
            //}

            return predicate;
        }
	}
}
